use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use crate::core::services::protocols::IContributionKeyword;
use super::multicast_stream::MulticastStream;

pub struct StreamsImplement {
    streams: Mutex<HashMap<String, Arc<MulticastStream>>>,
}

impl StreamsImplement {
    pub fn new() -> Self {
        Self {
            streams: Mutex::new(HashMap::new()),
        }
    }

    pub fn get_stream(&self, stream_name: &str) -> Option<Arc<MulticastStream>> {
        let mut streams = self.streams.lock().unwrap();
        if !streams.contains_key(stream_name) {
            let stream = Arc::new(MulticastStream::new(stream_name));
            streams.insert(stream_name.to_string(), stream);
        }
        streams.get(stream_name).cloned()
    }
}

impl IContributionKeyword for StreamsImplement {
    fn init(&self, _options: crate::core::services::protocols::ContributionKeywordInitOptions) {}
    fn request_contribution(&self, _ctx: std::sync::Arc<dyn crate::core::services::protocols::IRequestContributionContext>, _definitions: &[crate::core::manifest::ContributeDefinition]) {}
    fn request_revoke_contribution(&self, _ctx: std::sync::Arc<dyn crate::core::services::protocols::IRequestContributionContext>, _definitions: &[crate::core::manifest::ContributeDefinition]) {}
    fn request_contribution_point(&self, _ctx: std::sync::Arc<dyn crate::core::services::protocols::IRequestContributionContext>, _definitions: &[crate::core::manifest::ContributionPointDefinition]) {}
    fn request_revoke_contribution_point(&self, _ctx: std::sync::Arc<dyn crate::core::services::protocols::IRequestContributionContext>, _definitions: &[crate::core::manifest::ContributionPointDefinition]) {}
    fn get_context(&self, _contributor: &str) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> { None }
    fn destructor(&self) {}
}
